#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>
#include <fcntl.h>

int main()
{
  int pip[2];
  pipe(pip);
  pid_t pid;
  pid = fork();
  
  if(pid > 0)
  {
    wait(NULL);
   
    close(pip[1]);
    int fd = open("./1.txt",O_WRONLY | O_TRUNC);
    dup2(fd,STDOUT_FILENO);

    char data[20];
    int num;
    num = read(pip[0],data,20);
    write(STDOUT_FILENO,data,num);
    printf("\n");
  }

  else
  {
    close(pip[0]);
    char data[20];
    fsncanf(stdin,20 ,"%s",data );
    write(pip[1],data,strlen(data));
  }

  return 0;
}
